package com.ymatou.userservice.testcase;

import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.userservice.parameter.CheckThirdPartyUserIsNeedBindMobileDtoBean;
import com.ymatou.userservice.service.CheckThirdPartyUserIsNeedBindMobileDtoCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P3;
import com.ymttest.business.service.UserCallService;
import com.ymttest.database.sqlwapper.YmtUsersWapper;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.constant.ECode;
import com.ymttest.utils.constant.ThirdPartyType;
/**
*检查第三方账号是否需要绑定手机接口
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_CheckThirdPartyUserIsNeedBindMobileDto{
	private static CheckThirdPartyUserIsNeedBindMobileDtoBean checkthirdpartyuserisneedbindmobiledtoBean;
	private static CheckThirdPartyUserIsNeedBindMobileDtoCall checkthirdpartyuserisneedbindmobiledtoCall;
	private static YmtUsersWapper userWapper;
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("检查第三方账号是否需要绑定手机接口");
		userWapper = new YmtUsersWapper();
	}

	@Before
	public void caseUp() {
		checkthirdpartyuserisneedbindmobiledtoBean=new CheckThirdPartyUserIsNeedBindMobileDtoBean();
		checkthirdpartyuserisneedbindmobiledtoCall=new CheckThirdPartyUserIsNeedBindMobileDtoCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(checkthirdpartyuserisneedbindmobiledtoCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CheckThirdPartyUserIsNeedBindMobileDto_001() {
		Logger.start(true,"微博账号已经绑定过手机号码，返回不需要绑定");
		try {
			Map user = userWapper.selectThirdPartyBindPhone("Ymt_User_At_SinaWeibo", "YmatouUserId");
			checkthirdpartyuserisneedbindmobiledtoBean.setThirdPartyId(user.get("sWeiboUserId").toString());
			checkthirdpartyuserisneedbindmobiledtoBean.setThirdPartyType(ThirdPartyType.WEIBO);
			checkthirdpartyuserisneedbindmobiledtoCall.setData(checkthirdpartyuserisneedbindmobiledtoBean);
			checkthirdpartyuserisneedbindmobiledtoCall.callService();			
			Logger.verifyEquals(ECode.SUCCESS, checkthirdpartyuserisneedbindmobiledtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("true", checkthirdpartyuserisneedbindmobiledtoCall.getString("Success"), "验证是否成功");
			Logger.verifyEquals("不需要绑定手机", checkthirdpartyuserisneedbindmobiledtoCall.getString("SuccessMessage"), "验证Msg信息");
			Logger.verifyEquals(ECode.USER_NO, checkthirdpartyuserisneedbindmobiledtoCall.getString("Result"), "验证结果信息");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CheckThirdPartyUserIsNeedBindMobileDto_002() {
		Logger.start(true,"微信账号已经绑定过手机号码，返回不需要绑定");
		try {
			Map user = userWapper.selectThirdPartyBindPhone("Ymt_User_At_Wexin_Identify", "iYmtUserId");
			checkthirdpartyuserisneedbindmobiledtoBean.setThirdPartyId(user.get("sUnionId").toString());
			checkthirdpartyuserisneedbindmobiledtoBean.setThirdPartyType(ThirdPartyType.WEIXIN);
			checkthirdpartyuserisneedbindmobiledtoCall.setData(checkthirdpartyuserisneedbindmobiledtoBean);
			checkthirdpartyuserisneedbindmobiledtoCall.callService();			
			Logger.verifyEquals(ECode.SUCCESS, checkthirdpartyuserisneedbindmobiledtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("true", checkthirdpartyuserisneedbindmobiledtoCall.getString("Success"), "验证是否成功");
			Logger.verifyEquals("不需要绑定手机", checkthirdpartyuserisneedbindmobiledtoCall.getString("SuccessMessage"), "验证Msg信息");
			Logger.verifyEquals(ECode.USER_NO, checkthirdpartyuserisneedbindmobiledtoCall.getString("Result"), "验证结果信息");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CheckThirdPartyUserIsNeedBindMobileDto_003() {
		Logger.start(true,"阿里账号已经绑定过手机号码，返回不需要绑定");
		try {
			String phone=TestDataManager.getPhoneNum();
			String aliUserId = "IsBindAli_"+TestDataManager.getRandomNum(10);
			Map m=UserCallService.regByAli(aliUserId, phone, null, null);
			Thread.sleep(2000);
			checkthirdpartyuserisneedbindmobiledtoBean.setThirdPartyId(aliUserId);
			checkthirdpartyuserisneedbindmobiledtoBean.setThirdPartyType(ThirdPartyType.ALI);
			checkthirdpartyuserisneedbindmobiledtoCall.setData(checkthirdpartyuserisneedbindmobiledtoBean);
			checkthirdpartyuserisneedbindmobiledtoCall.callService();			
			Logger.verifyEquals(ECode.SUCCESS, checkthirdpartyuserisneedbindmobiledtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("true", checkthirdpartyuserisneedbindmobiledtoCall.getString("Success"), "验证是否成功");
			Logger.verifyEquals("不需要绑定手机", checkthirdpartyuserisneedbindmobiledtoCall.getString("SuccessMessage"), "验证Msg信息");
			Logger.verifyEquals(ECode.USER_NO, checkthirdpartyuserisneedbindmobiledtoCall.getString("Result"), "验证结果信息");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CheckThirdPartyUserIsNeedBindMobileDto_004() {
		Logger.start(false,"微博账号未绑定过手机号码，返回需要绑定");
		try {
			String weiboUser = "NotBind_"+TestDataManager.getRandomNum(10);
			checkthirdpartyuserisneedbindmobiledtoBean.setThirdPartyId(weiboUser);
			checkthirdpartyuserisneedbindmobiledtoBean.setThirdPartyType(ThirdPartyType.WEIBO);
			checkthirdpartyuserisneedbindmobiledtoCall.setData(checkthirdpartyuserisneedbindmobiledtoBean);
			checkthirdpartyuserisneedbindmobiledtoCall.callService();			
			Logger.verifyEquals(ECode.ERROR400, checkthirdpartyuserisneedbindmobiledtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("true", checkthirdpartyuserisneedbindmobiledtoCall.getString("Success"), "验证是否成功");
			Logger.verifyEquals("需要绑定手机", checkthirdpartyuserisneedbindmobiledtoCall.getString("SuccessMessage"), "验证Msg信息");
			Logger.verifyEquals(ECode.USER_YES, checkthirdpartyuserisneedbindmobiledtoCall.getString("Result"), "验证结果信息");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CheckThirdPartyUserIsNeedBindMobileDto_005() {
		Logger.start(false,"微信账号未绑定过手机号码，返回需要绑定");
		try {
			String unionId = "unbindweixin_"+TestDataManager.getRandomNum(10);
			String phone = TestDataManager.getPhoneNum();
			Map user = UserCallService.regByWeiXin(unionId, null, true, null);
			checkthirdpartyuserisneedbindmobiledtoBean.setThirdPartyId(user.get("thirdPartyId").toString());
			checkthirdpartyuserisneedbindmobiledtoBean.setThirdPartyType(ThirdPartyType.WEIXIN);
			checkthirdpartyuserisneedbindmobiledtoCall.setData(checkthirdpartyuserisneedbindmobiledtoBean);
			checkthirdpartyuserisneedbindmobiledtoCall.callService();			
			Logger.verifyEquals(ECode.ERROR400, checkthirdpartyuserisneedbindmobiledtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("true", checkthirdpartyuserisneedbindmobiledtoCall.getString("Success"), "验证是否成功");
			Logger.verifyEquals("需要绑定手机", checkthirdpartyuserisneedbindmobiledtoCall.getString("SuccessMessage"), "验证Msg信息");
			Logger.verifyEquals(ECode.USER_YES, checkthirdpartyuserisneedbindmobiledtoCall.getString("Result"), "验证结果信息");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CheckThirdPartyUserIsNeedBindMobileDto_006() {
		Logger.start(false,"阿里账号未绑定过手机号码，返回需要绑定");
		try {
			String weiboUser = "NotBind_"+TestDataManager.getRandomNum(4);
			checkthirdpartyuserisneedbindmobiledtoBean.setThirdPartyId(weiboUser);
			checkthirdpartyuserisneedbindmobiledtoBean.setThirdPartyType(ThirdPartyType.ALI);
			checkthirdpartyuserisneedbindmobiledtoCall.setData(checkthirdpartyuserisneedbindmobiledtoBean);
			checkthirdpartyuserisneedbindmobiledtoCall.callService();			
			Logger.verifyEquals(ECode.ERROR400, checkthirdpartyuserisneedbindmobiledtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("true", checkthirdpartyuserisneedbindmobiledtoCall.getString("Success"), "验证是否成功");
			Logger.verifyEquals("需要绑定手机", checkthirdpartyuserisneedbindmobiledtoCall.getString("SuccessMessage"), "验证Msg信息");
			Logger.verifyEquals(ECode.USER_YES, checkthirdpartyuserisneedbindmobiledtoCall.getString("Result"), "验证结果信息");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_CheckThirdPartyUserIsNeedBindMobileDto_007() {
		Logger.start(false,"未输入第三方账号，检查失败");
		try {
			checkthirdpartyuserisneedbindmobiledtoBean.setThirdPartyType(ThirdPartyType.ALI);
			checkthirdpartyuserisneedbindmobiledtoCall.setData(checkthirdpartyuserisneedbindmobiledtoBean);
			checkthirdpartyuserisneedbindmobiledtoCall.callService();			
			Logger.verifyEquals("100", checkthirdpartyuserisneedbindmobiledtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("false", checkthirdpartyuserisneedbindmobiledtoCall.getString("Success"), "验证是否成功");
//			Logger.verifyEquals("错误的请求参数", checkthirdpartyuserisneedbindmobiledtoCall.getString("LastErrorMessage"), "验证Msg信息");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
//	@Test
//	@Category(P1.class)
//	@TestCase
//	public void Tc_CheckThirdPartyUserIsNeedBindMobileDto_008() {
//		Logger.start(true,"微博老用户未绑定过手机号码，返回不需要绑定");
//		try {
//			Logger.comment("查找一个未绑定过手机号的微博账号");
//			Map user = userWapper.getThirdPartyNotBindPhone("Ymt_User_At_SinaWeibo", "YmatouUserId");
//			
//			checkthirdpartyuserisneedbindmobiledtoBean.setThirdPartyId(user.get("sWeiboUserId").toString());
//			checkthirdpartyuserisneedbindmobiledtoBean.setThirdPartyType(ThirdPartyType.WEIBO);
//			checkthirdpartyuserisneedbindmobiledtoCall.setData(checkthirdpartyuserisneedbindmobiledtoBean);
//			checkthirdpartyuserisneedbindmobiledtoCall.callService();			
//			Logger.verifyEquals(ECode.SUCCESS, checkthirdpartyuserisneedbindmobiledtoCall.getString("ResponseCode"), "验证Code");
//			Logger.verifyEquals("true", checkthirdpartyuserisneedbindmobiledtoCall.getString("Success"), "验证是否成功");
//			Logger.verifyEquals("不需要绑定手机", checkthirdpartyuserisneedbindmobiledtoCall.getString("SuccessMessage"), "验证Msg信息");
//			Logger.verifyEquals(ECode.USER_NO, checkthirdpartyuserisneedbindmobiledtoCall.getString("Result"), "验证结果信息");
//		} catch (Exception e) {
//			Logger.fail(e);
//		}
//	}
	
//	@Test
//	@Category(P1.class)
//	@TestCase
//	public void Tc_CheckThirdPartyUserIsNeedBindMobileDto_009() {
//		Logger.start(true,"微信老用户未绑定过手机号码，返回不需要绑定");
//		try {
//			Logger.comment("查找一个未绑定过手机号的微信账号");
//			Map user = userWapper.getThirdPartyNotBindPhone("Ymt_User_At_Wexin_Identify", "iYmtUserId");
//			
//			checkthirdpartyuserisneedbindmobiledtoBean.setThirdPartyId(user.get("sUnionId").toString());
//			checkthirdpartyuserisneedbindmobiledtoBean.setThirdPartyType(ThirdPartyType.WEIXIN);
//			checkthirdpartyuserisneedbindmobiledtoCall.setData(checkthirdpartyuserisneedbindmobiledtoBean);
//			checkthirdpartyuserisneedbindmobiledtoCall.callService();			
//			Logger.verifyEquals(ECode.SUCCESS, checkthirdpartyuserisneedbindmobiledtoCall.getString("ResponseCode"), "验证Code");
//			Logger.verifyEquals("true", checkthirdpartyuserisneedbindmobiledtoCall.getString("Success"), "验证是否成功");
//			Logger.verifyEquals("不需要绑定手机", checkthirdpartyuserisneedbindmobiledtoCall.getString("SuccessMessage"), "验证Msg信息");
//			Logger.verifyEquals(ECode.USER_NO, checkthirdpartyuserisneedbindmobiledtoCall.getString("Result"), "验证结果信息");
//		} catch (Exception e) {
//			Logger.fail(e);
//		}
//	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CheckThirdPartyUserIsNeedBindMobileDto_010() {
		Logger.start(true,"阿里老用户未绑定过手机号码，返回不需要绑定");
		try {
			Logger.comment("查找一个未绑定过手机号的阿里账号");
			Map user = userWapper.getThirdPartyNotBindPhone("Ymt_User_At_Alipay", "iYmtUserId");
			
			checkthirdpartyuserisneedbindmobiledtoBean.setThirdPartyId(user.get("sUserId").toString());
			checkthirdpartyuserisneedbindmobiledtoBean.setThirdPartyType(ThirdPartyType.ALI);
			checkthirdpartyuserisneedbindmobiledtoCall.setData(checkthirdpartyuserisneedbindmobiledtoBean);
			checkthirdpartyuserisneedbindmobiledtoCall.callService();			
			Logger.verifyEquals(ECode.SUCCESS, checkthirdpartyuserisneedbindmobiledtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("true", checkthirdpartyuserisneedbindmobiledtoCall.getString("Success"), "验证是否成功");
			Logger.verifyEquals("不需要绑定手机", checkthirdpartyuserisneedbindmobiledtoCall.getString("SuccessMessage"), "验证Msg信息");
			Logger.verifyEquals(ECode.USER_NO, checkthirdpartyuserisneedbindmobiledtoCall.getString("Result"), "验证结果信息");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
//	@Test
//	@Category(P1.class)
//	@TestCase
//	public void Tc_CheckThirdPartyUserIsNeedBindMobileDto_011() {
//		Logger.start(true,"wx老用户未绑定过手机号码，返回不需要绑定");
//		try {
//			Logger.comment("查找一个未绑定过手机号的阿里账号");
//			//select top 1* from Ymt_User_At_Wexin_Identify left join Ymt_MobilePhoneAccount on Ymt_User_At_Wexin_Identify.iYmtUserId=Ymt_MobilePhoneAccount.iUserId where Ymt_User_At_Wexin_Identify.IsBind=1 and Ymt_MobilePhoneAccount.sAccountName is null
//			String wx ="oA7HCt_RZRUAZzC5-Fw-yTtWH5s4";
//			checkthirdpartyuserisneedbindmobiledtoBean.setThirdPartyId(wx);
//			checkthirdpartyuserisneedbindmobiledtoBean.setThirdPartyType(ThirdPartyType.WEIXIN);
//			checkthirdpartyuserisneedbindmobiledtoCall.setData(checkthirdpartyuserisneedbindmobiledtoBean);
//			checkthirdpartyuserisneedbindmobiledtoCall.callService();			
//			Logger.verifyEquals(ECode.SUCCESS, checkthirdpartyuserisneedbindmobiledtoCall.getString("ResponseCode"), "验证Code");
//			Logger.verifyEquals("true", checkthirdpartyuserisneedbindmobiledtoCall.getString("Success"), "验证是否成功");
//			Logger.verifyEquals("不需要绑定手机", checkthirdpartyuserisneedbindmobiledtoCall.getString("SuccessMessage"), "验证Msg信息");
//			Logger.verifyEquals(ECode.USER_NO, checkthirdpartyuserisneedbindmobiledtoCall.getString("Result"), "验证结果信息");
//		} catch (Exception e) {
//			Logger.fail(e);
//		}
//	}
}